/*
 *
 * Created on: 07.01.2013
 *
 * ReleaseParser.cpp
 * This file is part of KOBUS
 * 
 * Copyright (C) 2012 - Ivan Penkin, MIPT
 * grek.penkin@gmail.com
 *
 * KOBUS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KOBUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KOBUS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 *  
 */

#include <DHReleaseParser.h>

using namespace kobus;
using namespace dhcp;


void DHReleaseParser::initializeByConfig() throw (Exception) {

  setRegex(
      config.getString(DHConfig::Keys::releaseParser::releaseRegex));
  setIpGrpNum(
      config.getInt(DHConfig::Keys::releaseParser::ipGrp));
  setMacGrpNum(
      config.getInt(DHConfig::Keys::releaseParser::macGrp));
}

HostInfo DHReleaseParser::getNewHostInfo() throw (Exception) {

  HostInfo info = getNewHostInfoWithoutFlags();
  info.setFlags(dhcp::Release);

  return info;
}

void DHReleaseParser::check() const throw (Exception) {

  if (bufers.hostInfo[Bufers::MAC].isEmpty()) {
    throw Exception(Exception::NO_ERRNO,
      "ReleaseParser::check(): Non-optional group 'mac' is empty. In message:"
        + bufers.message);
  }

  QHostAddress ip(bufers.hostInfo[Bufers::IP]);
  if (ip.isNull()) {
    throw Exception(Exception::NO_ERRNO,
      "ReleaseParser::check(): Non-optional group 'ip' is empty. In message:"
        + bufers.message);
  }
}
